package com.fs.controller;

import com.fs.pojo.OrderDetail;
import com.fs.service.OrderDetailService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.Condition;
import com.fs.vo.ResponseData;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 刘伟
 * @fileName OrderDetailController
 * @date 2024/10/19 9:36
 * @description
 **/
@RestController
@RequestMapping("/OrderDetail")
public class OrderDetailController {
    @Resource
    OrderDetailService orderDetailService;

    /**
     * 查询商品详情单的方法
     * @param condition
     * @return
     */
    @PostMapping("/list")
    public ResponseData<PageInfo<OrderDetail>> getOrderDetailList(@RequestBody Condition<OrderDetail> condition){
        PageInfo<OrderDetail> orderDetailList = orderDetailService.getOrderDetailList(condition);
        return orderDetailList!=null? ResponseDataUtil.buildOk(200,"操作成功",orderDetailList):ResponseDataUtil.buildFail(null);
    }

    /**
     * 添加商品详情单的方法
     * @param orderDetail
     * @return
     */
    @PutMapping
    public ResponseData<Integer> addOrderDetail(@RequestBody OrderDetail orderDetail){
        Integer count = orderDetailService.addOrderDetail(orderDetail);
        return count==1?ResponseDataUtil.buildOk(200,"添加成功",count):ResponseDataUtil.buildFail(null);
    }
    /**
     * 修改商品详情单的方法
     */
    @PostMapping
    public ResponseData<Integer> updateOrderDetail(@RequestBody OrderDetail orderDetail){
        Integer count = orderDetailService.updateOrderDetail(orderDetail);
        return count==1?ResponseDataUtil.buildOk(200,"修改成功",count):ResponseDataUtil.buildFail(null);
    }
    /**
     * 删除当前商品编号的商品详情的方法
     */
    @PostMapping("/del")
    public ResponseData<Integer> delOrderDetailById(@RequestBody OrderDetail orderDetail){
        Integer count = orderDetailService.delOrderDetailById(orderDetail);
        return count==1?ResponseDataUtil.buildOk(200,"删除成功",count):ResponseDataUtil.buildFail(null);
    }
}
